package com.changpay.zywy.wight

import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.example.havi.interfaces.HyphenateLibraryCallBack
import com.hyphenate.chat.EMMessage
import com.changpay.zywy.app.App
import com.changpay.zywy.ui.activity.main.MainActivity
import com.changpay.zywy.utils.NotificationConstants

/**
 * 封装环信库与主项目交互的方法
 */
class HyphenateLibraryCallBackHandle : HyphenateLibraryCallBack {


    override fun goUserHome(context: Context, userId: String) {

    }

    override fun onNewMsg(message: EMMessage) {
        if (App.isAppBackground()) {  //是否是后台运行 显示提醒通知
            val intent = Intent(App.instance, MainActivity::class.java)
            intent.addCategory(Intent.CATEGORY_LAUNCHER)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
            val pendingIntent = PendingIntent.getActivity(
                App.instance, 1, intent,
                PendingIntent.FLAG_UPDATE_CURRENT
            )
            NotificationHelper.getInstance()
                .sendNotification(NotificationConstants.HYPHENATE_NOTIFCATION_ID, "环信库", "您有新的聊天消息!", pendingIntent)
        }
    }
}
